package com.coocaa.app.lib.cleaner.scanner.config.impl;

import android.content.Context;
import android.os.Environment;

import com.coocaa.app.lib.cleaner.scanner.config.ConfigDataFactory;
import com.coocaa.app.lib.cleaner.scanner.config.ConfigManagerFactory;

import java.io.File;


/**
 * Created by lu on 17-4-17.
 */

public class NativeConfigLoader implements ConfigManagerFactory.ConfigLoader {

    public NativeConfigLoader() {
    }

    @Override
    public void init(Context context) {

    }

    @Override
    public ConfigDataFactory.ConfigData load() {
        ConfigDataFactory.ConfigData data = new ConfigDataImpl();
        {
            /*
            影视中心(以后教育中心会合并到过来):指定删除以下目录:
            1. /data/data/com.tianci.movieplatform/cache
            2. /data/data/com.tianci.movieplatform/iqiyi_p2p
            3. /mnt/sdcard/iqiyi_p2p/
            */
            String packageName = "com.tianci.movieplatform";
            data.appendPackageDel(packageName, "/data/data/" + packageName + "/iqiyi_p2p");
            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                data.appendPackageDel(packageName, Environment.getExternalStorageDirectory().getAbsolutePath() + "/iqiyi_p2p");

            data.appendCacheKeep(packageName);
        }
        {
//          优选购物：除“账户，支付，历史记录”不要删除，其他均可删除
//                     目前没有账户，支付的数据，所以先屏蔽历史记录
            String mallPackageName = "com.coocaa.mall";
            data.appendPackageKeep(mallPackageName, "/data/data/" + mallPackageName + "/databases/history_record_db");
        }
        {
//            酷游吧：除“广告，免责声明标志”不要删除，其他可以删除
//            应用圈：广告，免责声明，我的应用的排序，下载中的缓存不删除，其他可以删除
            String appstorePackageName = "com.tianci.appstore";
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/databases/app_table.db");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/databases/AdRes_DB");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/shared_prefs/ADList.xml");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/shared_prefs/table_kv.xml");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/shared_prefs/ADNextCall.xml");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/shared_prefs/AutoUninstall_CMD.xml");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/files/7_upgrade.apk");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/files/13_upgrade.apk");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/files/coocaa_app/download");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/files/silent_downloader");
            data.appendPackageKeep(appstorePackageName, "/data/data/" + appstorePackageName + "/files/cleaner_cloud_config.ini"); //存放垃圾的目錄，不能刪除
            try {
                String adPath = "/data/data/" + appstorePackageName + "/files/AD";
                if (new File(adPath).exists())
                    data.appendPackageKeep(appstorePackageName, adPath);
                if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + appstorePackageName + "/AD";
                    if (new File(path).exists())
                        data.appendPackageKeep(appstorePackageName, path);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return data;
    }
}
